"""
 Created by luogang on 2020/8/10
"""
from enum import Enum
from datetime import datetime


class LogLevel(Enum):
    DEBUG = 0
    INFO = 10
    WARN = 20
    ERROR = 30

    def __str__(self):
        if self == LogLevel.DEBUG:
            return "DEBUG"
        if self == LogLevel.INFO:
            return "INFO"
        if self == LogLevel.WARN:
            return "WARN"
        if self == LogLevel.ERROR:
            return "ERROR"

    def __repr__(self):
        return self.__str__()


class Logger:
    def __init__(self, name):
        self.name = name

    def debug(self, msg, *args):
        return self._print_log(msg, level=LogLevel.DEBUG)

    def info(self, msg, *args):
        return self._print_log(msg, *args)

    def warn(self, msg, *args):
        return self._print_log(msg, *args, level=LogLevel.WARN)

    def error(self, msg, *args):
        return self._print_log(msg, *args, level=LogLevel.ERROR)

    def _print_log(self, msg, *args, level=LogLevel.INFO):
        msg = str(msg)
        if len(args) > 0:
            msg = msg + ' ' + ' '.join([str(item) for item in args])

        output = f"[{datetime.now().strftime('%m-%d %H:%M:%S')}]-[{str(level)}]-[{self.name}] {msg}"
        print(output)


def get_logger(name):
    logger = Logger(name)
    return logger
